//
//  SaleTicketViewModel.m
//  didacar
//
//  Created by 度周末网络-王腾 on 15/12/28.
//  Copyright © 2015年 dzmmac. All rights reserved.
//

#import "SaleTicketViewModel.h"

@implementation SaleTicketViewModel

-(id)init{
    
    self.selectedTicketIndex = -1;
    self.saleTickets = [[NSMutableArray alloc ] init];
    return [super init];
}

/**
 *  获取用户可用的优惠券
 *
 *  @param resultBlock
 */
-(void)getMemberCouponsAll:(DealDataResultBlock)resultBlock{
    
    NSMutableDictionary *postDic = [[NSMutableDictionary alloc ] init];
    
    [postDic setObj:USERINFOManager.getUserInfo.MemberId forKey:@"MemberId"];
    [postDic setObj:@(self.pageIndex).stringValue forKey:@"PageIndex"];
    [postDic setObj:@(self.pageCount).stringValue forKey:@"PageSize"];
    
    WEAKSELF
    [[BaseHttpRequest sharedInstance] sendRequestToPost:@"Coupons.GetMemberCouponsAll" withData:postDic alertMessage:@"" success:^(NSDictionary *dicData) {
        
        
        if (weakSelf.pageIndex == 1) {
            [weakSelf.resultList removeAllObjects];
        }
        for (NSDictionary *entityDic in [dicData objectForKey:@"CouponsList"]) {
            CouponEntity *entity = [[CouponEntity alloc ] initWithDictionary:entityDic];
            [weakSelf.resultList addObject:entity];
        }
        
        resultBlock(1,nil,nil);
        
    } error:^(NSString *errorMsg) {
        resultBlock(0,nil,errorMsg);
    }];
}


/**
 *  获取下单可用的优惠券
 *
 *  @param resultBlock
 */
-(void)getMemberCouponsForOrder:(DealDataResultBlock)resultBlock{
    NSMutableDictionary *postDic = [[NSMutableDictionary alloc ] init];
    [postDic setObj:USERINFOManager.getUserInfo.MemberId forKey:@"MemberId"];
    [postDic setObj:@(self.LineType).stringValue forKey:@"LineType"];
    [postDic setObj:self.SendTime forKey:@"SendTime"];
    [postDic setObj:self.OrderAmount.stringValue forKey:@"OrderAmount"];
    
    WEAKSELF
    [[BaseHttpRequest sharedInstance] sendRequestToPost:@"Coupons.GetMemberCouponsForOrder" withData:postDic alertMessage:@"" success:^(NSDictionary *dicData) {
        for (NSDictionary *entityDic in [dicData objectForKey:@"CouponsList"]) {
            CouponEntity *entity = [[CouponEntity alloc ] initWithDictionary:entityDic];
            [weakSelf.resultList addObject:entity];
        }
        resultBlock(1,nil,nil);
    } error:^(NSString *errorMsg) {
        resultBlock(0,nil,errorMsg);
    }];
}

@end
